<template>
	<uni-data-select v-model="internalValue" :localdata="range" :clear="false" @change="handleChange" v-if="show"></uni-data-select>
</template>

<script>
	import * as API from '@/common/api';
	export default {
		name: "dictData",
		props: {
			dictType: {
				type: String,
				default: ''
			},
			dictValue: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				range: [],
				show: false,
				internalValue: '',
			};
		},
		created() {
			 this.getDictDataByCode(this.dictType);
		},
		methods: {
			async getDictDataByCode(dictType) {
				const res = await API.getDictDataByType(dictType);
				this.range = res.data.map(item => {
					return {
						value: item.dictValue,
						text: item.dictLabel
					}
				})
				this.show=true;
				
			},
			handleChange(val) {
				this.$emit('update:dictValue', val);
			},
		},
		watch: {
			dictValue: {
				handler(newVal) {
					this.internalValue = newVal;
				},
				immediate: true, // 立即执行一次，确保在组件初始化时也能同步
			},
		},
	}
</script>

<style>

</style>